* Bootstrap procedure over entire causal link:
capture program drop layersbootstrap
program define layersbootstrap, rclass

	preserve
	bsample , cluster(firmcode) idcluster(newfirmcode)
	
	sort newfirmcode t
	xtset newfirmcode t

	* GMM, ma(1) errors, one-step
	xtabond2 layers L.layers logsales sectordummy1-sectordummy8 yeardummy4-yeardummy12 if sample == 1, ///
	gmmstyle(L.layers, lag(3 .)) gmmstyle(logsales, lag(5 .)) robust
	return scalar layers_gmm = _b[L.layers]
	return scalar sales_gmm = _b[logsales]
	cap drop layers_gmm_all
	predict layers_gmm_all
	
	areg log2inequality1 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality1_gmm = _b[layers_gmm_all]
	areg log2inequality2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality2_gmm = _b[layers_gmm_all]
	areg log2inequality3 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality3_gmm = _b[layers_gmm_all]
	areg log2inequality4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality4_gmm = _b[layers_gmm_all]
	areg log2inequality5 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality5_gmm = _b[layers_gmm_all]
	areg wagegap1_topbottom_log layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_log_gmm = _b[layers_gmm_all]
	
	areg res2inequality1_model2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_gmm = _b[layers_gmm_all]
	areg res2inequality2_model2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_gmm = _b[layers_gmm_all]
	areg res2inequality3_model2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality3_gmm = _b[layers_gmm_all]
	areg res2inequality4_model2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_gmm = _b[layers_gmm_all]
	areg res2inequality5_model2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_gmm = _b[layers_gmm_all]
	areg wagegap1_topbottom_res2 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res2_gmm = _b[layers_gmm_all]
	
	areg res2inequality1_model4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_gmm_v2 = _b[layers_gmm_all]
	areg res2inequality2_model4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_gmm_v2 = _b[layers_gmm_all]
	areg res2inequality3_model4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality3_gmm_v2 = _b[layers_gmm_all]
	areg res2inequality4_model4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_gmm_v2 = _b[layers_gmm_all]
	areg res2inequality5_model4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_gmm_v2 = _b[layers_gmm_all]
	areg wagegap1_topbottom_res4 layers_gmm_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res4_gmm_v2 = _b[layers_gmm_all]
	
	restore
end
